<?php

class PluginsController extends Controller {
    var $name = 'Plugins';
    var $components = array('plugin', 'options');

    function index() {
        $this->action = 'plugins';
        $this->plugins();
    }

    function plugins($plugin = null, $action = null) {
        if (!empty($plugin)) {
            $redirect = false;
            switch ($action) {
                case 'activate':
                    activate_plugin($plugin);
                    $redirect = true;
                break;
                case 'deactivate':
                    deactivate_plugin($plugin);
                    $redirect = true;
                break;
                case 'done':
                    $this->header_notice = __('Action done.');
                break;
            }
            if ($redirect) {
                $this->redirect('/plugins/plugins/' . $plugin . '/done');
                exit();            
            }
        }
        $plugins = get_plugins();
        $this->set('plugins', $plugins);
    }
}
?>
